package com.carlinfo.userscenter.filter.back;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.catalina.connector.RequestFacade;

import com.carlinfo.userscenter.users.pojo.AAdmins;

public class AuthBackFilter implements Filter
{

	@Override
	public void destroy()
	{
		System.out.println("==AuthBackFilter==destroy=");
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
			throws IOException, ServletException
	{
		System.out.println(req + "==AuthBackFilter==doFilter==" + res);

		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) res;
		HttpSession session = request.getSession();
		AAdmins admins = (AAdmins) session.getAttribute("adminsSess");
		System.out.println("==session中的票==" + admins);

		if (admins != null)
		{
			chain.doFilter(req, res);
		} else
		{
			String info = "不能逃票";

			session.setAttribute("info", info);
			response.sendRedirect(request.getContextPath() + "/NoLoginBackServlet?method=login");
		}
	}

	@Override
	public void init(FilterConfig config) throws ServletException
	{
		System.out.println("==AuthBackFilter==init=");
	}

}
